package com.jvxb.manage.livable.controller;


import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.jvxb.manage.livable.entity.SysLog;
import com.jvxb.manage.livable.service.SysLogService;
import com.jvxb.common.web.RespMsg;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 * 系统日志表 前端控制器
 * </p>
 *
 * @author jvxb
 * @since 2020-06-07
 */
@RestController
@RequestMapping("/admin/v1/sysLog")
public class SysLogController {

    @Autowired
    private SysLogService logService;

    @GetMapping("listPage")
    public Object listPage(String name,
                           String content,
                           String startTime,
                           String endTime,
                           @RequestParam(defaultValue = "10") Integer size,
                           @RequestParam(defaultValue = "1") Integer current) {
        IPage<SysLog> page = new Page<>(current, size);
        QueryWrapper wrapper = new QueryWrapper();
        wrapper.like(StringUtils.isNotEmpty(name), SysLog.OPERATOR_NAME, name);
        wrapper.like(StringUtils.isNotEmpty(content), SysLog.CONTENT, content);
        if(StringUtils.isNotEmpty(startTime)) {
            wrapper.between(SysLog.CREATE_TIME, DateUtil.parse(startTime), DateUtil.parse(endTime));
        }
        wrapper.orderByDesc(SysLog.CREATE_TIME);
        logService.page(page, wrapper);
        return RespMsg.ok(page);
    }

}

